﻿#region Header

/*
Behavioral Rating of Dancing Human Crowds based on Motion Patterns
By

Pascal Hauser 
Dipl. Ing. in Informatik, Hochschule für Technik Rapperswil, 2006
Master Thesis, Hochschule für Technik Rapperswil, 2008-2010

and

Raphael Gfeller
Dipl. Ing. in Informatik, Hochschule für Technik Rapperswil, 2006
Master Thesis, Hochschule für Technik Rapperswil, 2008-2010

*/

#endregion

#region Usings

using System;
using Emgu.CV;
using Emgu.CV.Structure;
using paravili.Services;
using Sebarf.Services.Interfaces;

#endregion

namespace paravili.Steps {
	/// <summary>
	/// Description of the class
	/// </summary>
	public class LaplacianFilter : ProcessStepWithMeasurement<Image<Bgr, Byte>> {
		#region Public Properties

		[ConfigurabelBooleanValue(Name = "Is Enable LaplacianFilter")]
		public bool IsEnable { get; set; }

		[ConfigurabelStringValue(Name = "ImageProviderId")]
		public String ImageProviderId { get; set; }

		[ConfigurabelBooleanValue(Name = "ForwardImageToImageProvider")]
		public bool ForwardImageToImageProvider { get; set; }

		[ServiceRequest(IsOptional = true)]
		public IImageProviderService ImageProviderService { get; set; }

		#endregion

		#region Public Methods

		public LaplacianFilter() {
			ImageProviderId = "LaplacianFilter.ImageData";
			ForwardImageToImageProvider = false;
		}

		protected override Image<Bgr, byte> OnProcess(Image<Bgr, byte> toProcess) {
			Image<Bgr, byte> toReturn = toProcess;

			if (IsEnable) {
				// alternatively use the following line
				// toProcess.Laplace(xxx);
				toReturn =
					toProcess.Convert<Hsv, byte>()[2].Convolution(
						new ConvolutionKernelF(new float[3, 3] {
						                                       	{1.0f / 12, 1.0f / 6, 1.0f / 12}, {1.0f / 6, -1f, 1.0f / 6},
						                                       	{1.0f / 12, 1.0f / 6, 1.0f / 12}
						                                       })).Convert<Bgr, Byte>();
			}
			if (ForwardImageToImageProvider) {
				ImageProviderService.SetImage(ImageProviderId, toReturn.Convert<Lab, Byte>());
			}
			return toReturn;
		}

		#endregion

		#region Private Methods

		// private methods located here

		#endregion

		#region Private Fields

		// private fields located here

		#endregion
	}
}